<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
	
</head>
<body style="padding: 10px;">
	<form class="layui-form">
		<input type="hidden" name="id" value="{$data.id}">
		<input type="hidden" name="type" value="0">
		<div class="layui-form-item">
			<label class="layui-form-label">标题</label>
			<div class="layui-input-block">
				<input type="text" name="title" class="layui-input" value="{$data.title}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">排序</label>
			<div class="layui-input-block">
				<input type="text" name="ord" class="layui-input" value="{$data.ord}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">url</label>
			<div class="layui-input-block">
				<input type="text" name="url" class="layui-input" value="{$data.url}">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">&nbsp;</label>
			<div class="layui-form-inline">
				<button type="button" class="layui-btn " onclick="turn false;" id="upload_img">
 					<i class="layui-icon">-&#xe67c;</i>上传图片
			    </button>
			    <img src="{$data.img}" id="pre_img" style="height: 35px;" >
			    <input type="hidden" name="img" value="{$data.img}">
			</div>
		</div>
	
	</form>

	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" onclick="save()">保存</button>
		</div>
	</div>



	<script type="text/javascript">
		layui.use(['layer','form','upload'],function(){
			layer=layui.layer;
			form=layui.form;
			upload=layui.upload;
			$=layui.jquery;


		//执行实例
		var uploadInst = upload.render({
			elem: '#upload_img' //绑定元素
			,url: '/admins.php/admins/video/upload_img' //上传接口
			,accept:'images'
			,done: function(res){
			  //上传完毕回调
			  $('#pre_img').attr('src',res.msg);
			  $('input[name="img"]').val(res.msg);
			}
			,error: function(){
			  //请求异常回调
		    }
		    });
	    });


		//保存
		function save(){
			title=$.trim($('input[name="title"]').val());
			url=$.trim($('input[name="url"]').val());
			img=$.trim($('input[name="img"]').val());
			if(title==''){
				layer.alert('标题不能为空',{'icon':2,'anim':6});
				return;
			}
			if(url==''){
				layer.alert('url不能为空',{'icon':2,'anim':6});
				return;
			}
			if(img==''){
				layer.alert('请上传图片',{'icon':2,'anim':6});
				return;
			}
			$.post('/admins.php/admins/slide/save', $('form').serialize(), function(res){
				if(res.code>0){
					layer.alert(res.msg,{'icon':2});
				}else{
					layer.msg(res.msg,{'icon':1});
					setTimeout(function(){
						parent.window.location.reload();
					},1000);
				}
			},'json')


		}
	</script>
	
</body>
</html>